<template>
  <!--大小额贷记退汇录入-->
  <el-dialog :title="title" center :visible.sync="openState" width="1024px" :close-on-click-modal="false">
    <el-form ref="queryDetail" :model="form" :rules="rules" label-width="110px">
      <el-card class="form-card">
        <div slot="header" class="label-header-msg">
          <span>交易基础信息</span>
        </div>
        <el-row>

          <el-col :span="8">
            <el-form-item label="原交易流水号" prop="oriid">
              <el-input v-model="form.oriid" disabled/>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="原CPG日期" prop="oricpgdate">
              <el-date-picker v-model="form.oricpgdate" style="width: 100%" type="date" value-format="yyyyMMdd" disabled/>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="原工作日期" prop="oriworkdate">
              <el-date-picker v-model="form.oriworkdate" style="width: 100%" type="date" value-format="yyyyMMdd" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>

          <el-col :span="8">
            <el-form-item label="原系统编号" prop="orisyscode">
              <el-select style="width: 100%;" v-model="form.orisyscode" placeholder="原系统编号" disabled>
                <el-option
                  v-for="dict in dictMap.SYS_CODE"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="原业务优先级" prop="oribizProity" v-show="this.bizProityshow">
              <el-select style="width: 100%;" v-model="form.oribizProity" placeholder="原业务优先级" disabled>
                <el-option
                  v-for="dict in dictMap.PRIORITY3CODE"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="原报文类型" prop="pkgno">
              <el-select style="width: 100%;" v-model="form.pkgno" placeholder="原报文类型" disabled>
                <el-option
                  v-for="dict in dictMap.PKG_TYPE"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="原业务类型" prop="oribizTypeCode">
              <el-select
                style="width: 100%"
                v-model="
                  form.oribizTypeCode === null || form.oribizTypeCode === undefined
                    ? ''
                    : form.oribizTypeCode + '-' + form.oribizTypeCodeDesc
                "
                placeholder="原业务类型"
                :disabled="true"
              ></el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="原业务种类" prop="oribizCtgyCode">
              <el-select
                style="width: 100%"
                v-model="
                  form.oribizCtgyCode === null || form.oribizCtgyCode === undefined
                    ? ''
                    : form.oribizCtgyCode + '-' + form.oribizCtgyCodeDesc
                "
                placeholder="原业务种类"
                :disabled="true"
              ></el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="原交易货币" prop="oricurcd">
              <el-input v-model="form.oricurcd" placeholder="货币种类" :disabled="true"   disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="原金额" prop="oriamount">
              <ht-amount-input v-model="form.oriamount" placeholder="交易金额"  :disable="true"></ht-amount-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="大写金额" prop="bAmount">
              <ht-amount-upper :inputValue="form.oriamount" placeholder="交易金额" ></ht-amount-upper>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>



      <!--付款人信息-->
      <el-card class="form-card">
        <div slot="header" class="label-header-msg">
          <span>付款人信息</span>
        </div>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="原付款人账号" prop="oripayerActno">
              <el-input v-model="form.oripayerActno" placeholder="付款人账号" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="原付款人名称" prop="oripayerName">
              <el-input v-model="form.oripayerName" placeholder="付款人名称" disabled/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-oripayer">
              <el-form-item label="原付款行行号" prop="oripayerBrno">
                <el-input v-model="form.oripayerBrno" placeholder="原付款行行号" disabled/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="16">
            <el-form-item label="原付款行行名" prop="oripayerBrname" label-width="130px">
              <el-input v-model="form.oripayerBrname" placeholder="原付款行行名" disabled/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-oripayer">
              <el-form-item label="原付款人开户行号" prop="oripayerAccBrno">
                <el-input v-model="form.oripayerAccBrno" placeholder="付款人开户行行号" disabled/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="16">
            <el-form-item label="原付款人开户行行名" prop="oripayerAccBrname" label-width="130px">
              <el-input v-model="form.oripayerAccBrname" placeholder="付款人开户行行名" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>

      <!--收款人信息-->
      <el-card class="form-card">
        <div slot="header" class="label-header-msg">
          <span>收款人信息</span>
        </div>
        <el-row v-show="this.form.pkgno==='beps.382.001.01'||this.form.pkgno==='beps.382.001.02'">
          <el-col>
          <el-button type="primary" icon="el-icon-search" plain @click="openPayeeDialog()">
            报文明细查询
          </el-button>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="原收款人账号" prop="oripayeeActno">
              <el-input v-model="form.oripayeeActno" placeholder="原收款人账号" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="原收款人名称" prop="oripayeeName">
              <el-input v-model="form.oripayeeName" placeholder="原收款人账号" disabled/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-oripayee">
              <el-form-item label="原收款行行号" prop="oripayeeBrno">
                <el-input v-model="form.oripayeeBrno" placeholder="原付款行行号" disabled/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="16">
            <el-form-item label="原收款行行名" prop="oripayeeBrname" label-width="130px">
              <el-input v-model="form.oripayeeBrname" placeholder="原付款行行名" disabled/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="10">
          <el-col :span="8">
            <div class="grid-oripayee">
              <el-form-item label="原收款人开户行号" prop="oripayeeAccBrno">
                <el-input v-model="form.oripayeeAccBrno" placeholder="原收款人开户行行号" disabled/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="16">
            <el-form-item label="原收款人开户行行名" prop="oripayeeAccBrname" label-width="130px">
              <el-input v-model="form.oripayeeAccBrname" placeholder="原收款人开户行行名" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>

      <el-card class="form-card">
        <div slot="header" class="label-header-msg">
          <span>CIS信息</span>
        </div>
        <el-row>
          <el-col :span="12">
            <el-form-item label="原CIS委托日期" prop="oriCisDate">
              <el-date-picker v-model="form.oriCisDate" style="width: 100%;" type="date" value-format="yyyyMMdd" disabled/>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="原CIS交易序号" prop="oriCisSeqno">
              <el-input v-model="form.oriCisSeqno" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="原CIS票据号码" prop="oriCisNo">
              <el-input v-model="form.oriCisNo" :disabled="true" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="业务回执状态" prop="rtStatu">
              <el-select style="width: 100%;" v-model="form.rtStatu" placeholder="业务回执状态" disabled>
                <el-option
                  v-for="dict in dictMap.PROC_STATUS"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>

      <el-card class="form-card">
        <div slot="header" class="label-header-msg">
          <span></span>
        </div>
        <el-row>
          <el-col :span="12">
            <el-form-item label="业务优先级" prop="bizProity" v-show="this.bizProityshow">
              <el-select style="width: 100%;" v-model="form.bizProity" placeholder="业务优先级">
                <el-option
                  v-for="dict in dictMap.PRIORITY3CODE"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="退汇原因" prop="txRemarks">
              <el-input type="textarea" v-model="form.txRemarks" show-word-limit maxlength="135" />
            </el-form-item>
          </el-col>
        </el-row>

      </el-card>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirm">确定</el-button>
      <el-button @click="cancel">取消</el-button>
    </div>

    <detail382 ref="detail382" @confirm="confirmPayee"></detail382>

  </el-dialog>
</template>
<script>
import { detail, submit } from "@/api/cnaps/baseBiz/return/input/index";
import HtAmountInput from "@/views/components/HtAmountInput";
import HtAmountUpper from "@/views/components/HtAmountUpper";
import Detail382 from "@/views/cnaps/baseBiz/return/input/components/detail382";

export default {
  name: "Detail",
  components: {
    Detail382,
    HtAmountInput,HtAmountUpper
  },
  props: {
    dictMap: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      cardList: [],
      busTypeList: [],
      id: "",
      title: "",
      pkgNo: "",
      // 是否显示弹出层
      openState: false,
      bizProityshow: false,
      // 表单参数
      form: {},
      rules: {
        txRemarks: {required: true,message: "请输入退汇原因",trigger: "blur"}
      }
    };
  },
  watch: {
    dictMap: {
      handler(data) {},
    },
  },
  mounted() {
  },
  methods: {
    // 表单重置
    reset() {
      // this.resetForm("editForm");
      this.resetForm("queryDetail")
    },
    close() {
      this.openState = true;
    },
    // 关闭回掉
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          this.reset();
          done();
        })
        .catch((_) => {});
    },
    show(id = "", pkgNo = "") {
      let that = this;
      this.pkgNo = pkgNo;
      this.id = id;
      this.title = "大小额贷记退汇录入明细";
      if (id) {
        // 如果传了ID 这里查询一个已经存在的数据
        detail({
          id: this.id,
          pkgno: this.pkgNo,
        }).then((res) => {
          let tempForm = res.result.data;
          this.$set(this, "form", tempForm);
          this.$set(this.form,"pkgno",res.result.pkgno)
          this.openState = true;
          if(String(this.pkgNo).toLowerCase().indexOf('hvps')>-1){
            this.bizProityshow=true
          }else if(String(this.pkgNo).toLowerCase().indexOf('beps')>-1){
            this.bizProityshow=false
          }
        });
      }
    },

    cancel() {
      this.openState = false;
      this.reset();
      this.$emit("editComplete", false);
    },
    /** TODO提交按钮 */
    confirm: function () {
      let formData = this.form;
      //如果有ID 则是修改
      if (this.id) {
        formData.id = this.id;
        formData.pkgno = this.pkgNo;
        this.$refs["queryDetail"].validate((valid) => {
          if (valid) {
            submit(formData).then((res) => {
              this.msgSuccess("提交成功");
              this.$emit("editComplete", true);
              this.reset();
              this.openState = false;
            });
          }
        });
      }
    },


    openPayeeDialog() {
      this.$refs.detail382.show(this.form.oriid);
    },

    confirmPayee(row) {
        this.$set(this.form, "oripayeeBrno", row.payeeBrno);
        this.$set(this.form, "oripayeeBrname", row.payeeBrname);
        this.$set(this.form, "oripayeeAccBrno", row.payeeBrno);
        this.$set(this.form, "oripayeeAccBrname", row.payeeBrname);
        this.$set(this.form, "oripayeeActno", row.payeeActno);
        this.$set(this.form, "oripayeeName", row.payeeName);
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
